﻿using System;
using System.IO.IsolatedStorage;
using TheVerge.Base.Platform;

namespace TheVerge.Phone.Imp
{
    public class PhoneLocalStorage : ILocalStorage
    {
        public void LoadSetting(string key, Action<object> onLoaded, Action<Exception> onError)
        {
            try
            {
                if (IsolatedStorageSettings.ApplicationSettings.Contains(key))
                {
                    onLoaded(IsolatedStorageSettings.ApplicationSettings[key]);
                }
                else
                {
                    onLoaded(null);
                }
            }
            catch (Exception exp)
            {
                onError(exp);
            }
        }

        public void StoreSetting(string key, object value, Action onFinished, Action<Exception> onError)
        {
            try
            {
                IsolatedStorageSettings.ApplicationSettings[key] = value;
                onFinished();
            }
            catch (Exception exp)
            {
                onError(exp);
            }
        }
    }
}
